﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Projektarbete
{
    /// <summary>
    /// Creates a new camera instance for tracking objects or players
    /// </summary>
    static class Camera
    {
        public static Vector2 position;
        public static float zoom;

        private static Matrix viewMatrix;
        public static Matrix getViewMatrix
        {
            get { return viewMatrix; }
        }

        private static int viewportWidth;
        private static int viewportHeight;

        private static Point maxCulling;

        public static void Initialize(Vector2 Position, Vector2 viewport, Point mapSize)
        {
            position = Position;
            zoom = 1.0f;

            maxCulling = new Point(mapSize.X * 24 - 400, mapSize.Y * 24 - 300);

            viewMatrix = Matrix.Identity;

            viewportHeight = (int)viewport.Y;
            viewportWidth = (int)viewport.X;
        }

        /// <summary>
        /// Update the view matrix
        /// </summary>
        /// <param name="position">Point to look at</param>
        public static void UpdateMatrix(Vector2 Position)
        {
            position = new Vector2(Position.X + 4, Position.Y - 12);
            //Vector2 newPosition = new Vector2(MathHelper.Clamp(position.X, 400, maxCulling.X), MathHelper.Clamp(position.Y, 300, maxCulling.Y));
            viewMatrix = Matrix.CreateTranslation(new Vector3(-position.X, -position.Y, 0)) *
                         Matrix.CreateScale(new Vector3(zoom, zoom, 1)) *
                         Matrix.CreateTranslation(new Vector3(viewportWidth * 0.5f, viewportHeight * 0.5f, 0));
        }
    }
}
